<?php
$connect = mysqli_connect('localhost','root','root','thinkcmf');
mysqli_set_charset($connect,'utf8');
if(!$connect){
    echo '数据库连接失败';
    die;
}
$file = $_FILES['image'];
// 取出后缀名
$ext = strrchr($file['name'],'.');
// 新命名
$newName = mt_rand(0000,9999).time().$ext;
// 保存路径
$Path = "uploads/images/".$newName;
$result = move_uploaded_file($file['tmp_name'], $Path);
if ($result == 1 ){
        echo json_encode(['code' => 1, 'msg' => '上传成功' , 'data' => ['path' => 'uploads/images/'.$newName]]);
    }else{
        echo json_encode(['code' => 2, 'msg' => '上传失败' , 'data' => '']);
    }
